//
//  MediaView.m
//  HorizonLight
//
//  Created by lanou on 15/9/24.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "MediaView.h"

@implementation MediaView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSomeButtons];
    }
    return self;

}
-(void)addSomeButtons
{

    //返回按钮
    self.backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self setUpAllButton:self.backBtn frame:CGRectMake(20, 10, kIconWidth, kIconHeight) image:@"btn_back_normal"];
    
    //标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.backBtn.right + kDistance, 10, kScreenHight / 2, kIconHeight)];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont systemFontOfSize:17.0];
    [self addSubview:self.titleLabel];
    
    
    //分享按钮
    self.shareBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self setUpAllButton:self.shareBtn frame:CGRectMake(kScreenHight - kIconWidth - 20 ,10,  kIconWidth, kIconHeight) image:@"Entypo_e715(0)_32"];
    
    //点赞按钮
    self.clickZanBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self setUpAllButton:self.clickZanBtn frame:CGRectMake(_shareBtn.left - kIconWidth - kDistance, 10, kIconWidth, kIconHeight) image:@"Entypo_2661(0)_32"];
    
    //截图
    self.screenshotBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self setUpAllButton:self.screenshotBtn frame:CGRectMake(_clickZanBtn.left - kIconWidth - kDistance, 10, kIconWidth, kIconHeight) image:@"Entypo_d83d(0)_32"];

    
    //筛选高清
    self.seleteBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.seleteBtn.backgroundColor = [UIColor cyanColor];
    [self setUpAllButton:self.seleteBtn frame:CGRectMake(_screenshotBtn.left - kIconWidth - kDistance, 10, kIconWidth, kIconHeight) image:nil];
    
    //下一个
    self.nextBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self setUpAllButton:self.nextBtn frame:CGRectMake(kScreenHight - kIconWidth - 40, (kScreenWidth - kIconHeight ) / 2, 50, 50) image:@"btn_next@3x"];
    //播放按钮
    self.playBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self setUpAllButton:self.playBtn frame:CGRectMake((kScreenHight - kIconWidth) / 2, (kScreenWidth - kIconHeight ) / 2, 50, 50) image:@"btn_pause_iPad@2x"];
    
    //当前时间
    self.currentTime = [[UILabel alloc] initWithFrame:CGRectMake(20, kScreenWidth - kIconHeight - kDistance, kIconWidth + 10, kIconHeight)];
    self.currentTime.backgroundColor = [UIColor redColor];
    self.currentTime.text = @"00:00";
    [self setTimeLabel:self.currentTime];
    
    //总时间
    self.durationTime = [[UILabel alloc] initWithFrame:CGRectMake(kScreenHight - kIconWidth - 40, kScreenWidth - kIconHeight - kDistance, kIconWidth + 10, kIconHeight )];
    self.durationTime.backgroundColor = [UIColor cyanColor];
    self.durationTime.text = @"00:00";
    [self setTimeLabel:self.durationTime];
  
    //进度条
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, kScreenHight - kIconWidth * 4- 30, 2)];
    self.slider.minimumTrackTintColor = [UIColor cyanColor];
    self.slider.maximumTrackTintColor = [UIColor clearColor];
    //缓冲条
    self.progress = [[UIProgressView alloc] initWithFrame:CGRectMake(40 + kIconWidth, kScreenWidth - kIconHeight  , kScreenHight - kIconWidth * 4- 30, 50)];
    [self.progress setProgressTintColor:[UIColor yellowColor]];
//    self.progress.progress = 200;
    [self.progress setProgressViewStyle:(UIProgressViewStyleDefault)];
    [self.progress addSubview:self.slider];
    [self addSubview:self.progress];
  
    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(Hidden) userInfo:nil repeats:NO];
}
- (void)setTimeLabel:(UILabel *)timeLabel
{
    timeLabel.textColor = [UIColor whiteColor];
    timeLabel.font = [UIFont systemFontOfSize:15.0];
    [self addSubview:timeLabel];

}
- (void)setUpAllButton:(UIButton *)button frame:(CGRect)frame image:(NSString *)image
{
    button.frame = frame;
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setTintColor:[UIColor whiteColor]];
    [self addSubview:button];
    
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (self.backBtn.hidden == NO)
    {
        [self.backBtn setHidden:YES];
        [self.titleLabel setHidden:YES];
        [self.seleteBtn setHidden:YES];
        [self.screenshotBtn setHidden:YES];
        [self.clickZanBtn setHidden:YES];
        [self.shareBtn setHidden:YES];
        [self.playBtn setHidden:YES];
        [self.nextBtn setHidden:YES];
        [self.currentTime setHidden:YES];
        [self.durationTime setHidden:YES];
        [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(Hidden) userInfo:nil repeats:NO];
        
    }
    else
    {
        [self.backBtn setHidden:NO];
        [self.titleLabel setHidden:NO];
        [self.seleteBtn setHidden:NO];
        [self.screenshotBtn setHidden:NO];
        [self.clickZanBtn setHidden:NO];
        [self.shareBtn setHidden:NO];
        [self.playBtn setHidden:NO];
        [self.nextBtn setHidden:NO];
        [self.currentTime setHidden:NO];
        [self.durationTime setHidden:NO];
    }
}

//-(void)setUpTimer
//{
//    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(Hidden) userInfo:nil repeats:NO];
//
//}
-(void)Hidden
{
    [self.backBtn setHidden:YES];
    [self.titleLabel setHidden:YES];
    [self.seleteBtn setHidden:YES];
    [self.screenshotBtn setHidden:YES];
    [self.clickZanBtn setHidden:YES];
    [self.shareBtn setHidden:YES];
    [self.playBtn setHidden:YES];
    [self.nextBtn setHidden:YES];
    [self.currentTime setHidden:YES];
    [self.durationTime setHidden:YES];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
